<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #shop-car li {
            border: 1px dotted red;
            margin: 20px 0;
            padding: 20px;
        }

        .container {
            width: 400px;
            padding: 20px;
        }
    </style>

    <div class="container">

        <ul id="shop-car">
            <!-- <li>
                <input type="checkbox" />
                <div>商品名称:</div>
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg" alt="">
                <div>商品价格:50</div>
                <div class="num">购买数量:30</div>
                <div>商品规格: 黑</div>
                <div class="di">是否选中：不选中</div>
            </li> -->
        </ul>
        <p id="totalnum">总数量：</p>

    </div>

    <script>
        let shop = document.getElementById("shop-car");
        let div = document.getElementsByClassName("container")[0];

        console.log(shop);

        let products = [
            {
                goods_name: '小米10-1',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '500',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 10,
                goods_is_checked: true
            },
            {
                goods_name: '小米10-2',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '510',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 50,
                goods_is_checked: false
            }
        ]
        for (let i = 0; i < products.length; i++) {
            shop.innerHTML += `<li>
                <input type="checkbox" />
                <div>商品名称:${products[i].goods_name}</div>
                <img src="${products[i].goods_img}" alt="">
                <div>商品价格:${products[i].goods_price}</div>
                <div class="num">购买数量:${products[i].goods_num}</div>
                <div>商品规格: ${products[i].goods_attr}</div>
                <div class="di">是否选中：${products[i].goods_is_checked ? "选中" : "未选中"} </div>
            </li>
            `;
        }
        let input = document.getElementsByTagName("input");
        let di = document.getElementsByClassName("di");
        let num = document.getElementsByClassName("num")[0];
        let totalnum = document.querySelector("#totalnum");
        console.log(input, di, totalnum);
        var curNum = 0;
        for (let i = 0; i < input.length; i++) {
            input[i].onclick = function () {
                if (this.checked) {
                    console.log(i);
                    console.log(11);
                    di[i].innerHTML = `是否选中：选中了`
                    curNum += products[i].goods_num;
                    totalnum.innerHTML = `总数量${curNum}`
                } else {
                    curNum -= products[i].goods_num;
                    di[i].innerHTML = `是否选中：不选中`
                    totalnum.innerHTML = `总数量${curNum}`
                }
            }
        }
        console.log(products[0].goods_attr);

        // 作业2
        let persons = [
            {
                username: '张飞',
                sex: '男',
                salary: 50000
            },
            {
                username: '关羽',
                sex: '男',
                salary: 60000
            }
        ]
        let cur = JSON.parse(JSON.stringify(persons));
        for(let i=0;i<cur.length;i++){
            cur[i].salary += 2000;

        }
       /*  Array.from(cur).forEach(function (now) {
            now.salary += 2000;
        }) */
        console.log(persons,cur);



// 作业3
var jsonData = {

id: 42,

status: "OK",

data: ["刘杰", "男"]

};
let {id,status,data}=jsonData;
console.log(id,status,data);


// 作业4
function f(){
   return [1,3,5,7];
   }
   let [,a,b]=f();
   console.log(a,b);
</script>


</body>

</html>